<!--
 * @页面名称:工作台
 * @描述: 
 * @作者: 
 * @Date:
-->
<template>
  <div class="deskTop">
    <!-- 按钮组 -->
    <!-- <div class="button-group">
      <el-button @click="save" type="primary">保存</el-button>
    </div> -->
    <div>
      <ztree :setting="treeSetting.setting" :nodes="treeSetting.treeData" @onCreated="onCreated"></ztree>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, nextTick, onMounted } from "vue";
import useCurrentInstance from "@/utils/useCurrentInstance";
import Ztree from "@/components/ztree/Ztree.vue";

const { proxy } = useCurrentInstance();
// 父级表格数据
const tabClickFromParent = ref();
// tree配置
const treeSetting = reactive({
  setting: {
    // ztree配置
    data: {
      simpleData: {
        enable: true,
        idKey: "MS_ID"
      },
      key: {
        checked: "IsCheck",
        name: "MS_ModuleName"
      }
    },
    check: {
      enable: true
    },
    view: {
      showIcon: false
    }
  },
  treeData: [],
  ztreeObj: {} as any
});
// ztree初始化事件
const onCreated = (ztreeObj: any) => {
  treeSetting.ztreeObj = ztreeObj;
};
// 获取菜单数据
const getDeskTopData = (record: any) => {
  tabClickFromParent.value = record;
  proxy.$vueAxios.get("MasterPermission/GetModuleSet", { gid: record.G_ID }, { noLoading: true }).then((res: any) => {
    treeSetting.treeData = res.List;
  });
};
// 保存
const save = () => {
  const nodes = treeSetting.ztreeObj.getCheckedNodes();
  proxy.$vueAxios
    .post("MasterPermission/SetGUPermissionModuleSet", {
      g_ID: tabClickFromParent.value.G_ID,
      msIdList: nodes.map((item: any) => item.MS_ID)
    })
    .then((res: any) => {
      if (res.Mark) {
        proxy.$message.success("保存成功");
      } else {
        proxy.$message.error("保存失败");
      }
    });
};
// 将函数暴露给父组件
defineExpose({ getDeskTopData, save });
</script>

<style scoped lang="scss">
.deskTop {
  height: calc(100vh - 140px);
  padding-right: 6px;
  overflow-y: scroll;
}
</style>
